//
//  ActivityCell.m
//  mendianjieke
//
//  Created by 响当当 on 8/2/19.
//  Copyright © 2019 dongzheng. All rights reserved.
//

#import "ActivityCell.h"

@interface ActivityCell()<UIScrollViewDelegate>
@property (nonatomic, strong)UIButton *checkButton;//查看
@property (nonatomic, strong)UILabel *titleLabel;//活动标题
@property (nonatomic, strong)UILabel *activityLabel;//活动
@property (nonatomic, strong)UILabel *timeLabel;//活动时间
@property (nonatomic, strong)UILabel *flowLabel;//流量
@property (nonatomic, strong)UIScrollView *bannerView;

@property (nonatomic, strong)NSArray *infoArr;
@end

@implementation ActivityCell

- (NSArray *)infoArr
{
    if (!_infoArr)
    {
        _infoArr = [[NSArray alloc]init];
    }
    return _infoArr;
}

- (UIButton *)checkButton
{
    if (!_checkButton)
    {
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(15*kUIScaleBasePlus, 13*kUIScaleBasePlus,3*kUIScaleBasePlus,15*kUIScaleBasePlus)];
        lineView.backgroundColor = LCHexColor(0xFF7A17);
        lineView.layer.masksToBounds = YES;
        lineView.layer.cornerRadius = lineView.frame.size.width/2;
        [self.contentView addSubview:lineView];
        
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(lineView.frame)+5*kUIScaleBasePlus,10*kUIScaleBasePlus,80*kUIScaleBasePlus,21*kUIScaleBasePlus)
                                               textAligment:NSTextAlignmentLeft
                                                   textClor:LCHexColor(0x282828)
                                                   textFont:15*kUIScaleBasePlus];
        titleLabel.text = @"活动专区";
        [self.contentView addSubview:titleLabel];
        
        
        _checkButton = [Utilties creatButtonWithFrame:CGRectMake(SCREEN_WIDTH-16*kUIScaleBasePlus-80*kUIScaleBasePlus,12*kUIScaleBasePlus,100*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                         textAligment:UIControlContentHorizontalAlignmentLeft
                                                 text:@"立即查看"
                                             textClor:LCHexColor(0xFF7A17)
                                            buttonBGC:[UIColor clearColor]
                                             textFont:13*kUIScaleBasePlus
                                               target:self
                                               method:@selector(check)];
        [_checkButton setImage:[UIImage imageNamed:@"checkArrow"] forState:UIControlStateNormal];
        _checkButton.hidden = YES;
        [_checkButton setLeftTitleAndRightImageWithSpace:1];
        
        UIView *View = [[UIView alloc]initWithFrame:CGRectMake(0,41*kUIScaleBasePlus,SCREEN_WIDTH,1*kUIScaleBasePlus)];
        View.backgroundColor = JSALineColor;
        [self.contentView addSubview:View];
    }
    return _checkButton;
}

- (UIScrollView *)bannerView
{
    if (!_bannerView)
    {
        _bannerView = [[UIScrollView alloc]initWithFrame:CGRectMake(0,42*kUIScaleBasePlus,SCREEN_WIDTH-20*kUIScaleBasePlus,107*kUIScaleBasePlus)];
        _bannerView.bounces = NO;
        _bannerView.pagingEnabled = YES;
        _bannerView.delegate = self;
        _bannerView.showsHorizontalScrollIndicator = NO;
//        [_bannerView setContentOffset:CGPointMake(SCREEN_WIDTH, 0)];
    }
    return _bannerView;
}

- (UILabel *)titleLabel
{
    if (!_titleLabel)
    {
        _titleLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,CGRectGetMaxY(self.checkButton.frame)+27*kUIScaleBasePlus,100*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentLeft
                                           textClor:LCHexColor(0x282828)
                                           textFont:14*kUIScaleBasePlus];
        _titleLabel.text = @"520，我的爱";
    }
    return _titleLabel;
}

- (UILabel *)activityLabel
{
    if (!_activityLabel)
    {
        _activityLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(self.titleLabel.frame)+15*kUIScaleBasePlus,CGRectGetMaxY(self.checkButton.frame)+27*kUIScaleBasePlus,50*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentCenter
                                              textClor:LCHexColor(0xFFFFFF)
                                              textFont:12*kUIScaleBasePlus];
        _activityLabel.backgroundColor = LCHexColor(0xFF7A17);
        _activityLabel.layer.masksToBounds = YES;
        _activityLabel.layer.cornerRadius = 4;
        _activityLabel.text = @"活动中";
    }
    return _activityLabel;
}


- (UILabel *)timeLabel
{
    if (!_timeLabel)
    {
        _timeLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,CGRectGetMaxY(self.activityLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentLeft
                                          textClor:LCHexColor(0x686868)
                                          textFont:13*kUIScaleBasePlus];
        _timeLabel.text = @"活动时间：2019-02-28～2019";
    }
    return _timeLabel;
}

- (UILabel *)flowLabel
{
    if (!_flowLabel)
    {
        _flowLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus,CGRectGetMaxY(self.timeLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentLeft
                                          textClor:LCHexColor(0x686868)
                                          textFont:13*kUIScaleBasePlus];
        _flowLabel.text = @"活动流量：287827热度 活动成交：289298元";
    }
    return _flowLabel;
}

- (void)setFrame:(CGRect)frame
{
    frame.origin.x += 10*kUIScaleBasePlus;
    
    frame.size.width -= 2 * 10*kUIScaleBasePlus;
    
    [super setFrame:frame];
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.layer.cornerRadius = 10;
        self.layer.masksToBounds = YES;
        
        [self.contentView addSubview:self.checkButton];
        [self.contentView addSubview:self.bannerView];
//        [self.contentView addSubview:self.titleLabel];
//        [self.contentView addSubview:self.activityLabel];
//        [self.contentView addSubview:self.timeLabel];
//        [self.contentView addSubview:self.flowLabel];

    }
    
    return self;
}

#pragma mark - Method
- (void)check
{
    
}

- (void)getActivityInfo:(NSArray *)arr
{
 
    self.infoArr = arr;
    
    self.bannerView.contentSize = CGSizeMake((SCREEN_WIDTH-20*kUIScaleBasePlus)* (arr.count), 107*kUIScaleBasePlus);
    
    CGFloat width = SCREEN_WIDTH-20*kUIScaleBasePlus;

    for (int i=0; i<arr.count; i++)
    {
        ActivityModel *model = [[ActivityModel alloc]initWithDic:arr[i]];
        
        UILabel *titleLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus+width*i,15*kUIScaleBasePlus,100*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                       textAligment:NSTextAlignmentLeft
                                           textClor:LCHexColor(0x282828)
                                           textFont:14*kUIScaleBasePlus];
        titleLabel.text = model.name;
        [self.bannerView addSubview:titleLabel];
        [titleLabel sizeToFit];
        
        UILabel *activityLabel = [Utilties creatLabelWithFrame:CGRectMake(CGRectGetMaxX(titleLabel.frame)+15*kUIScaleBasePlus,15*kUIScaleBasePlus,50*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                          textAligment:NSTextAlignmentCenter
                                              textClor:LCHexColor(0xFFFFFF)
                                              textFont:12*kUIScaleBasePlus];
        activityLabel.backgroundColor = LCHexColor(0xFF7A17);
        activityLabel.layer.masksToBounds = YES;
        activityLabel.layer.cornerRadius = 4;
        activityLabel.text = @"活动中";
        [self.bannerView addSubview:activityLabel];

        UILabel *timeLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus+width*i,CGRectGetMaxY(activityLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentLeft
                                          textClor:LCHexColor(0x686868)
                                                  textFont:13*kUIScaleBasePlus];
        timeLabel.text = [NSString stringWithFormat:@"%@~%@",[Utilties getTime:model.startTime.stringValue],[Utilties getTime:model.endTime.stringValue]];
        [self.bannerView addSubview:timeLabel];

        UILabel *flowLabel = [Utilties creatLabelWithFrame:CGRectMake(15*kUIScaleBasePlus+width*i,CGRectGetMaxY(timeLabel.frame)+10*kUIScaleBasePlus,SCREEN_WIDTH-30*kUIScaleBasePlus,20*kUIScaleBasePlus)
                                      textAligment:NSTextAlignmentLeft
                                          textClor:LCHexColor(0x686868)
                                          textFont:13*kUIScaleBasePlus];
        flowLabel.text = [NSString stringWithFormat:@"活动流量：%@热度 活动成交：%@元",model.peopleCount.stringValue,model.totalAmount.stringValue];
        [self.bannerView addSubview:flowLabel];
    }
}

//完成拖拽
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //偏移到了第几个图片
//    NSInteger pageBtn = scrollView.contentOffset.x/(SCREEN_WIDTH - 20*kUIScaleBasePlus);
//
//    if (pageBtn == self.infoArr.count) {//偏移到第五个图片时
//
//        pageBtn = 0;
//
//        CGPoint resultPoint = CGPointMake((SCREEN_WIDTH - 20*kUIScaleBasePlus), 0);//偏移量移动到第一个图片(前面有第0个图片)
//
//        [self.bannerView setContentOffset:resultPoint animated:NO];//关闭动画效果
//
////        pageC.currentPage = pageBtn;//将pageControl挪到第1一个
//
//    } else if (pageBtn == 0) {//偏移到第五个图片时
//
//        pageBtn = self.infoArr.count-1;
//
//        CGPoint resultPoint = CGPointMake((SCREEN_WIDTH - 20*kUIScaleBasePlus)*4, 0);//偏移量移动到第五个图片(后面有第六个图片)
//
//        [self.bannerView setContentOffset:resultPoint animated:NO];
//
////        pageC.currentPage = pageBtn-1;//将pageControl挪到最后一个
//
//    } else {//正常拖动时，因为初始偏移量为WIDTH，所以所有pageControl都减1
//
////        pageC.currentPage = pageBtn-1;
//
//    }
    
    
}

@end
